package event.listen;

import javax.swing.*;

public class ButtonEven extends JFrame {

    private JButton b1, b2;

    public ButtonEven(){
        this.setSize(500, 500);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);

        b1 = new JButton("变红");
        b1.setBounds(100, 100,100, 100);

        b2 = new JButton("变绿");
        b2.setBounds(100, 200,100, 100);

        // 创建事件监听器
        ButtonEventListener be = new ButtonEventListener(this);

        // 给按钮添加事件监听器
        b1.addActionListener(be);
        b2.addActionListener(be);

        this.setLayout(null);

        this.add(b1);
        this.add(b2);
        this.setVisible(true);
    }
}
